package org.builder.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;

import org.builder.xml.Menu;
import org.dynobjects.core.ResourceResolver;
import org.xml.sax.SAXException;

public class MenuServiceImpl implements MenuService {

	private Map menuMap = new HashMap();
	
	private String xmlConfig ;
	
	private UnmarshallService menuUnmarshallService ;
	
	
	


	public void setXmlConfig(String xmlConfig) {
		this.xmlConfig = xmlConfig;
	}


	public void initMenu() throws Exception{
		ResourceResolver rr = new ResourceResolver();
		InputStream in = rr.resolve(xmlConfig);
		List<Menu> menuList = (List<Menu>) menuUnmarshallService.unmarshall(in,ArrayList.class);
		for (Iterator iter = menuList.iterator(); iter.hasNext();) {
			Menu menu = (Menu) iter.next();
			menuMap.put(menu.getName(), menu);
		}
	}
	

	public Map getMenuMap() {
		return menuMap;
	}


	
	/**
	 * SPRING
	 */
	
	public void setMenuUnmarshallService(UnmarshallService menuUnmarshallService) {
		this.menuUnmarshallService = menuUnmarshallService;
	}
}
